package com.yige.service.mongoService

import com.mongodb.DBCollection
import com.mongodb.DBObject
import com.yige.common.SystemConstant
import com.yige.service.GoodsClassService
import org.springframework.stereotype.Service

/**
 * Created by sunhao on 2015/10/9 0009.
 */

@Service
class MongoGoodsClassService extends BasicMongoServiceImp implements GoodsClassService{

    @Override
    DBCollection getCollection() {
        return mongoTemplate.getCollection(SystemConstant.MONGODB_COL_GOODS_CLASS)
    }


    @Override
    boolean reduceCountForGoods(Object _id, int n) {
        def goods = findOneById(_id) as DBObject
        goods.count = goods.count - n
        updateOne(_id, goods)
        return true
    }

    @Override
    boolean createCountForGoods(Object _id, int n) {
        def goods = findOneById(_id) as DBObject
        goods.put("count", goods.count + n)
        updateOne(_id, goods)
        return true
    }
}
